/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ejb.negocio;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.ejb.persistencia.Usuarios;

/**
 *
 * @author MoisesAntonio
 */
@Stateless
public class UsuariosFacade extends AbstractFacade<Usuarios> {
    @PersistenceContext(unitName = "PruebaLoginPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UsuariosFacade() {
        super(Usuarios.class);
    }
    
    public List<Usuarios> buscar(String id){
        return em.createQuery("SELECT c FROM Usuarios c WHERE c.nombreUsuario LIKE :id").setParameter("id", id).getResultList();
    }
    
    public int buscarNumero(String id){
        return em.createQuery("SELECT c FROM Usuarios c WHERE c.nombreUsuario LIKE :id").setParameter("id", id).getResultList().size();
    }
    
    public Usuarios login(String id, String pass){
        List<Usuarios> user=em.createQuery("SELECT c FROM Usuarios c WHERE c.nombreUsuario=:id AND c.pass=:pass").setParameter("id", id).setParameter("pass", pass).getResultList();
        if(user.size()==1){
            return user.get(0);
        }
        return null;
    }
    
}
